<?php

/**
 * Adding a SupportCase
 * @package ModuleAssistance
 * @version 1.0b
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

try {
	// Format purposes
	$date = explode('/', $_POST['date']);
	$date = $date[2].'-'.$date[1].'-'.$date[0];
	
	// Creating supportcase
	$supportcase = new SupportCase();
	$supportcase->content = $_POST['content'];
	$supportcase->priority = $_POST['priority'];
	$supportcase->status = $_POST['status'];
	$supportcase->progress = $_POST['progress'];
	$supportcase->title = $_POST['title'];
	$supportcase->contactId = $_POST['contact'];
	$supportcase->crmuserId = $_POST['owner'];
	$supportcase->date = $date.' '.$_POST['hour'];
	
	// Inserting supportcase into database
	$supportcase->SaveNew();
	
	echo 'OK';

} catch (Exception $e) {
	echo $e->getMessage();
}
?>